package com.yjd.bi.statistic.control;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yjd.bi.comm.service.ICityService;
import com.yjd.bi.comm.utils.BiDateUtil;
import com.yjd.bi.report.enums.StatisticsTypeEnum;
import com.yjd.bi.report.model.EChartsMapModel;
import com.yjd.bi.user.service.IUserStatisticsConditionService;
import com.yjd.comm.annotation.ServiceRemoteProxy;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.rpm.RpmServiceKeyEnum;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.FrameUtil;

@Controller
@Scope("prototype")
@RequestMapping("/area/")
public class AreaControl extends BaseControl{

    @ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
    private IUserStatisticsConditionService userStatisticsConditionService;
    @ServiceRemoteProxy(serviceUrlResouceKey = RpmServiceKeyEnum.RPM_BI_SERVICE_KEY)
    private ICityService cityService;

	@RequestMapping("index")
	public String deal() throws Exception {
        request.setAttribute("start", "2013-12-21");
        request.setAttribute("cityList", cityService.getModelList(FrameUtil.newHashMap("parentid", 0, "sort", " id asc"), DbWREnums.READ));
        request.setAttribute("now", BiDateUtil.initBiDate());
		return "area.index";
	}
	
	/**
	 * 查询地域相关数据统计
	 * @param timeType
	 * @param timeFrom
	 * @throws Exception
	 */
	@RequestMapping("getDatasByField")
	public void getDatasByField(String queryType) throws Exception{
		StatisticsTypeEnum statisticsType=StatisticsTypeEnum.getStatisticsType(queryType);
		EChartsMapModel ec=this.userStatisticsConditionService.getUserNumByArea(statisticsType);
		String aa = FrameUtil.json(ec);
		this.successData(FrameUtil.newHashMap("option",ec));
	}

	/**
	 * 根据yyyy-MM-dd转为long格式的yyyyMMdd
	 * @return
	 */
	public String getTime(String time){
		return DateUtil.timestampToDateString(DateUtil.dateStringToTimestamp(time, DateUtil.PATTERN_yyyy_MM_dd), DateUtil.PATTERN_yyyyMMdd);
	}
}
